# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html
from scrapy.exporters import CsvItemExporter
import logging
import os
# 写出数据
class QcwuyouPipeline(object):
    def open_spider(self,spider):
        
        spider.log("初始化输出文件:"+spider.savepath,logging.WARN)
        self.out = open(spider.savepath,"wb")

        self.export = CsvItemExporter(self.out,include_headers_line=True,encoding="utf-8")
        self.export.start_exporting()

        
    def process_item(self, item, spider):
        self.export.export_item(item)
        return item
    def close_spider(self,spider):
        self.export.finish_exporting()
        self.out.close()